package event

import (
	"go-admin-server/app/dao"
	"go-admin-server/app/dao/model"
	"log"
)

const (
	LevelTodo  = 0
	LevelInfo  = 1
	LevelWarn  = 2
	LevelError = 3
)

// 记录事件
func Add(level int, title, message string) {
	eventLog := model.EventLog{
		Title:   title,
		Message: message,
		Level:   level,
	}
	err := dao.DB.Debug().Create(&eventLog).Error
	if err != nil {
		log.Printf("记录事件错: %v", err)
	}
}

func Todo(title, message string) {
	Add(LevelTodo, title, message)
}

func Info(title, message string) {
	Add(LevelInfo, title, message)
}

func Warn(title, message string) {
	Add(LevelWarn, title, message)
}

func Error(title, message string) {
	Add(LevelError, title, message)
}
